package com.peanut.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.domain.po.TabItemPO;
import com.peanut.domain.vo.TabItemVO;
import com.peanut.service.TabItemService;
import com.peanut.mapper.TabItemMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author 王晓菲
* @description 针对表【tab_item】的数据库操作Service实现
* @createDate 2022-05-31 15:25:24
*/
@Service
public class TabItemServiceImpl extends ServiceImpl<TabItemMapper, TabItemPO>
    implements TabItemService{

    @Resource
    private TabItemMapper itemMapper;

    @Override
    public TabItemVO getItemByID(Long itemId) {
        TabItemPO tabItemPO = itemMapper.selectById(itemId);
        TabItemVO vo = new TabItemVO();
        BeanUtils.copyProperties(tabItemPO,vo);
        return vo;
    }

    @Override
    public List<TabItemVO> getItemContry(Integer itemContry) {
        List<TabItemPO> poList = itemMapper.selectList(new QueryWrapper<TabItemPO>().eq("item_contry", itemContry));
        List<TabItemVO> list = new ArrayList<>();
        for (TabItemPO tabItemPO : poList) {
            TabItemVO vo = new TabItemVO();
            BeanUtils.copyProperties(tabItemPO,vo);
            list.add(vo);
        }
        return list;
    }
}




